import { request } from '@/utils/request'
import type { IntervalStrDTO, PageDTO, PageRes, SortDTO } from '@/types/global'
import type {
  AddPermissionDTO,
  PermissionDTO,
  QueryPermissionDTO,
  RolePermission,
  UpdatePermissionDTO
} from '@/types/permission'

export function queryPermissionList(
  params: PageDTO & SortDTO & IntervalStrDTO & QueryPermissionDTO
) {
  return request.get<PageRes<PermissionDTO>>('/api/permission', { params })
}

export function addPermission(data: AddPermissionDTO) {
  return request.post('/api/permission', data)
}

export function getPermissionById(id: number) {
  return request.get<PermissionDTO>('/api/permission/' + id)
}

export function updatePermission(data: UpdatePermissionDTO) {
  return request.put('/api/permission', data)
}

export function queryAllPermission() {
  return request.get<RolePermission[]>('/api/permission/queryAllPermission')
}

export function deletePermissionByIds(idList: any) {
  return request.delete('/api/permission', {
    params: {
      idList: idList
    }
  })
}

export interface Menu {
  id: number
  path?: string
  icon: string
  name: string
  children?: Menu[]
}

export function queryMenu() {
  return request.get<Menu[]>('/api/permission/queryMenu')
}

export function queryPMenu() {
  return request.get<Menu[]>('/api/permission/queryPMenu')
}
